function output = bestResult(image, item)
%shows the best matches

Options.upright=true;
Options.tresh=0.0004;
% Load image
I.image = imread(image);
% Get Key Points
I.ipts = OpenSurf(I.image,Options);
% Put the landmark descriptors in a matrix
I.desc = reshape([I.ipts.descriptor],64,[]);

errs=zeros(length(item),length(I.ipts));
cor1s=zeros(length(item),length(I.ipts));
cor2s=zeros(length(item),length(I.ipts));
best = 1;
for k = 1:length(item)
    % Find the best matches      
      cor1=1:length(I.ipts); 
      cor2=zeros(1,length(I.ipts));
      for i=1:length(I.ipts)
          distance=sum((item(k).desc-repmat(I.desc(:,i),[1 length(item(k).ipts)])).^2,1);
          [err(i),cor2(i)]=min(distance);
      end
    % Sort matches on vector distance
      [err, ind]=sort(err); 
      cor1=cor1(ind); 
      cor2=cor2(ind);
    errs(k,:)=err;
    cor1s(k,:)=cor1;
    cor2s(k,:)=cor2;
    if(mean(err(1:10))<mean(errs(best,1:10)))
        best = k;
    end
end
  
% Show both images
  width = size(I.image,2) + size(item(best).image,2);
  if(size(I.image,1) > size(item(best).image,1))
      height = size(I.image,1);
  else
      height = size(item(best).image,1);
  end
  Im = zeros([height width size(item(best).image,3)]);
  Im(1:size(I.image,1),1:size(I.image,2),:)=I.image; 
  Im(1:size(item(best).image,1),size(I.image,2)+1:size(I.image,2)+size(item(best).image,2),:)=item(best).image;
  figure
  imshow(Im/255); 
  hold on;
% Find the number of best mathes
  limit=0;
  for i=1:length(errs(best, :))
      if(errs(best,i)<0.07)
          limit=i;
      end    
  end
 
% Show the best matches
  for i=1:limit,
      c=rand(1,3);
      plot([I.ipts(cor1s(best,i)).x item(best).ipts(cor2s(best,i)).x+size(I.image,2)],[I.ipts(cor1s(best,i)).y item(best).ipts(cor2s(best,i)).y],'-','Color',c)
      plot([I.ipts(cor1s(best,i)).x item(best).ipts(cor2s(best,i)).x+size(I.image,2)],[I.ipts(cor1s(best,i)).y item(best).ipts(cor2s(best,i)).y],'o','Color',c)
  end
  matches = limit
  result = best
  
  iptsmatch = item(best).ipts(cor2s(best,1:limit));
  for i=1:limit
      iptsx(i) = iptsmatch(i).x;
  end
  meanx = mean(iptsx)
  for i=1:limit
     if(iptsx(i)>(meanx+1000))
         iptsx(i) = iptsx(i)-length(item(11).image);
     end
  end
  meanx = mean(iptsx)   %sorted sort(iptsx);
  position = round(360*meanx/size(item(best).image,2))
  output = iptsmatch;